package cn.lizemin.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lzm
 * @Date 2024/7/21
 * @description
 */
@WebServlet("/user")
public class UserServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        // 通过content-type响应头告知客户端自己返回的是什么类型的数据，让浏览器根据合适的方式渲染
        resp.setContentType("text/html;charset=utf-8");
        // resp.setContentType("text/css");

        String username = req.getParameter("username");
        System.out.printf("received request: %s\n", username);
        try (PrintWriter writer = resp.getWriter()) {
            if ("admin".equals(username)) {
                writer.println("<h1>yes</h1>");
            } else {
                writer.println("<h1>no</h1>");
            }
        }
    }



}
